import numpy as np
import matplotlib
matplotlib.use('Agg') 
import pylab as pl
from mpltools import style
style.use('ggplot')


def main():
    print 'main'
    roc()
    pr()

def roc():
    print 'ROC'
    file_name = '/Users/rockyrock/Desktop/'+'roc'+".pdf"
    
    label = "DBN-Egonet2"
    roc_auc = 0.8670
    fpr = np.load('/Users/rockyrock/Desktop/n_results/2/15/stratified.pdf_raw__fpr_.npy')
    tpr = np.load('/Users/rockyrock/Desktop/n_results/2/15/stratified.pdf_raw__tpr_.npy')
    pl.plot(fpr, tpr, lw=1, color='red',label='%s (auc = %0.4f)' % (label, roc_auc))
    
    label = "LoReg-Egonet2"
    roc_auc = 0.9457
    fpr = np.load('/Users/rockyrock/Desktop/n_results/2/36/_clfid_0_stratified.pdf_loc__fpr_.npy')
    tpr = np.load('/Users/rockyrock/Desktop/n_results/2/36/_clfid_0_stratified.pdf_loc__tpr_.npy')
    pl.plot(fpr, tpr, lw=1, ls='--', color='red', label='%s (auc = %0.4f)' % (label, roc_auc))
    
    
    label = "DBN-Egonet13"
    roc_auc = 0.8606
    fpr = np.load('/Users/rockyrock/Desktop/n_results/13/15/stratified.pdf_raw__fpr_.npy')
    tpr = np.load('/Users/rockyrock/Desktop/n_results/13/15/stratified.pdf_raw__tpr_.npy')
    pl.plot(fpr, tpr, lw=1, color='green', label='%s (auc = %0.4f)' % (label, roc_auc))
    
    label = "LoReg-Egonet13"
    roc_auc = 0.9282
    fpr = np.load('/Users/rockyrock/Desktop/n_results/13/36/_clfid_0_stratified.pdf_loc__fpr_.npy')
    tpr = np.load('/Users/rockyrock/Desktop/n_results/13/36/_clfid_0_stratified.pdf_loc__tpr_.npy')
    pl.plot(fpr, tpr, lw=1, ls='--', color='green', label='%s (auc = %0.4f)' % (label, roc_auc))
    
#     label = "Egonet-10 without sampling"
#     roc_auc = 0.9792
#     fpr = np.load('/Users/rockyrock/Desktop/n_results/10/34/_clfid_0_stratified.pdf_local__fpr_.npy')
#     tpr = np.load('/Users/rockyrock/Desktop/n_results/10/34/_clfid_0_stratified.pdf_local__tpr_.npy')
#     pl.plot(fpr, tpr, lw=1, color='blue', label='%s (auc = %0.4f)' % (label, roc_auc))
#     
#     label = "Egonet-10 with sampling"
#     roc_auc = 0.9781
#     fpr = np.load('/Users/rockyrock/Desktop/mx/sampling/10/34/_clfid_0_stratified.pdf_loc+glob__fpr_.npy')
#     tpr = np.load('/Users/rockyrock/Desktop/mx/sampling/10/34/_clfid_0_stratified.pdf_loc+glob__tpr_.npy')
#     pl.plot(fpr, tpr, lw=1, ls='--', color='blue', label='%s (auc = %0.4f)' % (label, roc_auc))
    
    pl.plot([0, 1], [0, 1], 'k--')
    pl.xlim([-0.05, 1.05])
    pl.ylim([-0.05, 1.05])
    pl.xlabel('False Positive Rate')
    pl.ylabel('True Positive Rate')
    pl.title('Receiver operating characteristic')
    pl.legend(loc="lower right")
    pl.tight_layout()
    pl.savefig(file_name,dpi=72)
    
    
def pr():
    pl.clf()
    print 'PR'
    file_name = '/Users/rockyrock/Desktop/'+'prrrr'+".pdf"
    
    label = "DBN-Egonet2"
    pr_auc = 0.4061
    recall = np.load('/Users/rockyrock/Desktop/n_results/2/15/stratified_PR_.png_raw__rec_.npy')
    precision = np.load('/Users/rockyrock/Desktop/n_results/2/15/stratified_PR_.png_raw__prec_.npy')
    pl.plot(recall, precision, color='red', label='%s (auc = %0.4f)' % (label, pr_auc))
    
    label = "LoReg-Egonet2"
    pr_auc = 0.6224
    recall = np.load('/Users/rockyrock/Desktop/n_results/2/36/_clfid_0_stratified_PR_.png_loc__rec_.npy')
    precision = np.load('/Users/rockyrock/Desktop/n_results/2/36/_clfid_0_stratified_PR_.png_loc__prec_.npy')
    pl.plot(recall, precision, ls='--', color='red', label='%s (auc = %0.4f)' % (label, pr_auc))
    
    label = "DBN-Egonet13"
    pr_auc = 0.5311
    recall = np.load('/Users/rockyrock/Desktop/n_results/13/15/stratified_PR_.png_raw__rec_.npy')
    precision = np.load('/Users/rockyrock/Desktop/n_results/13/15/stratified_PR_.png_raw__prec_.npy')
    pl.plot(recall, precision, color='green', label='%s (auc = %0.4f)' % (label, pr_auc))
    
    label = "LoReg-Egonet13"
    pr_auc = 0.6813
    recall = np.load('/Users/rockyrock/Desktop/n_results/13/36/_clfid_0_stratified_PR_.png_loc__rec_.npy')
    precision = np.load('/Users/rockyrock/Desktop/n_results/13/36/_clfid_0_stratified_PR_.png_loc__prec_.npy')
    pl.plot(recall, precision, ls='--', color='green', label='%s (auc = %0.4f)' % (label, pr_auc))
    
#     label = "Egonet-10 without sampling"
#     pr_auc = 0.8514
#     recall = np.load('/Users/rockyrock/Desktop/n_results/10/34/_clfid_0_stratified_PR_.png_local__rec_.npy')
#     precision = np.load('/Users/rockyrock/Desktop/n_results/10/34/_clfid_0_stratified_PR_.png_local__prec_.npy')
#     pl.plot(recall, precision, color='blue', label='%s (auc = %0.4f)' % (label, pr_auc))
#     
#     label = "Egonet-10 with sampling"
#     pr_auc = 0.8521
#     recall = np.load('/Users/rockyrock/Desktop/mx/sampling/10/34/_clfid_0_stratified_PR_.png_loc+glob__rec_.npy')
#     precision = np.load('/Users/rockyrock/Desktop/mx/sampling/10/34/_clfid_0_stratified_PR_.png_loc+glob__prec_.npy')
#     pl.plot(recall, precision, ls='--', color='blue', label='%s (auc = %0.4f)' % (label, pr_auc))
    
    
    pl.xlabel('Recall')
    pl.ylabel('Precision')
    pl.ylim([0.0, 1.05])
    pl.xlim([0.0, 1.0])
    pl.title('Precision-Recall curve')
    pl.legend(loc="lower left")
    pl.tight_layout()
    pl.savefig(file_name,dpi=72)
    
    
main()










